<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>读卡页面</title>
    <script src="js\Jquery3.1.1.js"></script>
    <script src="layui/layui.js" type="text/javascript" charset="utf-8"></script>
    <script src="layui/lay/modules/layer.js" type="text/javascript" charset="utf-8"></script>
    <link rel="stylesheet" type="text/css" href="layui/css/modules/layer/default/layer.css"/>
    <link rel="stylesheet" type="text/css" href="layui/css/layui.css"/>
</head>
<body>
<OBJECT ID="MyActiveX1" WIDTH=0 HEIGHT=0 CLASSID="CLSID:38BEF3F4-E284-4548-8E7B-FE20AE443AD8">
    <PARAM NAME="_Version" VALUE="65536">
    <PARAM NAME="_ExtentX" VALUE="2646">
    <PARAM NAME="_ExtentY" VALUE="1323">
    <PARAM NAME="_StockProps" VALUE="0">
</OBJECT>
    <div class="container-fluid">
        <button id="btnStart" onclick="OnOpen()" class="layui-btn ">开启</button>
        <button  onclick="OnInventory()" class="layui-btn ">盘点</button>
        <button  onclick="StopInventory()" class="layui-btn ">停止</button>
    </div>
<script>
    var pandian=null;
    window.onload=function(){
        var devCnt = MyActiveX1.RDR_GetLoadedReaderDriverCount();
    }
    function OnOpen() {
        var nret = -1;
        // var sOpenType = OpenType[OpenType.selectedIndex].text;
        // var sDevName = DeviceType[DeviceType.selectedIndex].text;
        var sOpenType = "USB";
        var sDevName = "M201";
        if(sOpenType=="COM")
        {
            var sComName = ComName[ComName.selectedIndex].text;
            var sBaud = BaudVal[BaudVal.selectedIndex].text;
            var sFrame = FramVal[FramVal.selectedIndex].text;
            nret = MyActiveX1.RDR_OpenPort(sDevName,sComName,sBaud,sFrame);
        }
        else if(sOpenType=="USB")
        {
            nret = MyActiveX1.RDR_OpenUSB(sDevName,0,"");
        }
        else if(sOpenType=="NET")
        {
            var sIp = IPAddr.value;
            var nPort = nPortVal.value;
            nret = MyActiveX1.RDR_OpenNet(sDevName,sIp,nPort);
        }
        if(nret==0)
        {
            console.log("开启成功");
        }
        else
        {
            alert("打开设备失败!");
        }
    }

    function OnInventory()
    {
        pandian=setInterval(function () {
                var nret=0;
                var recordCnt=0;
                var j=0;
                nret = MyActiveX1.RDR_InitInventory();
                if(nret!=0)
                {
                    return ;
                }
                nret = MyActiveX1.RDR_Enable15693(0,0x00,0);
                if(nret!=0)
                {
                    MyActiveX1.RDR_FinishInventory();
                    return;
                }
                nret = MyActiveX1.RDR_Inventory(0,"");
                if(nret!=0)
                {
                    MyActiveX1.RDR_FinishInventory();
                    return;
                }
                recordCnt = MyActiveX1.RDR_GetRecordCnt();
                for(j=0;j<recordCnt;j++)
                {
                    var sTagInfo = MyActiveX1.GetRecord(j).split("-");
                    var sTagID = sTagInfo[sTagInfo.length-1];
                    console.log(sTagID);
                }
                MyActiveX1.RDR_FinishInventory();
        },100);
    }
    function StopInventory() {
        console.log("停止盘点");
        clearInterval(pandian);
    }
</script>
</body>
</html>